﻿using System;
using System.Collections.Generic;
using System.Linq;
using Infinity.Compilers;
using Infinity.Language.EditorDemo.Visitor;
using Infinity.Parser.Lexical;
using Infinity.Parser.Syntax;
using Infinity.Statements.StatementFactory;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Infinity.Statements.Block;
using System.Common.Extensions;

namespace Infinity.Language.EditorDemo
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
		}

		protected LexicalParser LexicalParser { get; set; }
		protected StatementFactory StatementFactory { get; set; }

		protected Compiler Compiler { get; set; }

		private void PART_CompileButton_Click(object sender, RoutedEventArgs e)
		{
			LexicalParser.ErrorList.Clear();
			LexicalParser.SetSource(PART_CodeEditor.Text, 0);

			var parser = new SyntaxParser(LexicalParser, StatementFactory);
			parser.Parse();

			PART_ErrorListBox.ItemsSource = LexicalParser.ErrorList;

			SyntaxTreeVisitor visitor = new SyntaxTreeVisitor();
			PART_TreeView.Items.Clear();
			PART_TreeView.Items.Add(visitor.Visit(parser.StartStatement));
		}

		private void Window_Initialized(object sender, EventArgs e)
		{
			Compiler = new Compiler();

			var list = new Stack<object>();

			list.Push(1);
			list.Push(2);
			list.Push(3);
			list.Push(4);
			list.Push(5);
			list.Push(6);
			list.Push("Hello World");
			list.Push(true);
			list.Push(7);
			list.Push(8);

			PART_StackItemsControl.ItemsSource = list;
			PART_QueueItemsControl.ItemsSource = list;

			PART_SetItemsControl.ItemsSource = list;

			
		}
	}
}
